package org.happy.tester.catcher.web.controller;

import org.happy.tester.common.http.req.MockResultRequest;
import org.happy.tester.common.http.resp.BaseResponse;
import org.happy.tester.catcher.service.MockService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Classname MockController
 * @Description TODO
 * @Date 2020/4/6 9:09 下午
 * @Created by jc.bai
 */
@RestController
@RequestMapping(value = "/catcher")
public class MockController {

    @Resource
    private MockService mockService;

    @GetMapping(value = "/mock/result/get")
    public BaseResponse<Object> getMockResult(String pointcut) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        Object mockResult = mockService.getMockResult(pointcut);
        baseResponse.setData(mockResult);
        return baseResponse.success();
    }

    @GetMapping(value = "/mock/need/get")
    public BaseResponse<Boolean> needMock(String pointcut) {
        BaseResponse<Boolean> baseResponse = new BaseResponse<>();
        boolean needMock = mockService.needMock(pointcut);
        baseResponse.setData(needMock);
        return baseResponse.success();
    }

    @PostMapping(value = "/mock/result/fix", produces = "application/json;charset=utf-8")
    public BaseResponse fixMockResult(@RequestBody List<MockResultRequest> mockResultRequestList) {
        mockService.fixMockResult(mockResultRequestList);
        return new BaseResponse().success();
    }
}
